<?php
namespace app\stock\controller;
use think\Controller;

class Index extends Controller
{

    // 定义属性 1 - 12月的时间
    protected $timeList = [];
    
    public function __construct(){
        parent::__construct();

        $year = date('Y');

        for($i = 1;$i <= 12;$i++)
        {
            $time = strtotime($year . '-' . $i);

            $start = strtotime(date('Y-m-01',$time));
 
            $end = strtotime(date('Y-m-t',$time));

            $this->timeList[] = ['start' => $start,'end' => $end];
        }
    }

    public function total(){
        /* 
            订单总数
            订单金额总数
            用户总数
        */

        $OrderCount=model('product.order.Order')->count();
        $OrderMoney=model('product.order.Order')->sum('amount');
        $BusinessCount=model('business.Business')->count();

        $data=[
            'OrderCount'=>$OrderCount,
            'OrderMoney'=>$OrderMoney,
            'BusinessCount'=>$BusinessCount
        ];

        $this->success('查询数据成功',null,$data);
    }

    public function business()
    {
        // 未认证数据
        $noCertified = [];

        // 已认证数据
        $Certified = [];

        // 循环
        foreach($this->timeList as $item)
        {
            $noCertifiedWhere = [
                'auth' => 0,
                'createtime' => ['between',[$item['start'],$item['end']]]
            ];

            $noCertified[] = model('business.Business')->where($noCertifiedWhere)->count();

            $CertifiedWhere = [
                'auth' => 1,
                'createtime' => ['between',[$item['start'],$item['end']]]
            ];

            $Certified[] = model('business.Business')->where($CertifiedWhere)->count();
        }

        $data = [
            'noCertified' => $noCertified,
            'Certified' => $Certified
        ];

        $this->success('查询数据成功',null,$data);

    }
}
